package com.qmx.launcher.activity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.qmx.launcher.QMXApplication;
import com.qmx.launcher.R;
import com.qmx.launcher.bean.Command;
import com.qmx.launcher.bean.DrawBoardPoint;
import com.qmx.launcher.bean.SelectColor;
import com.qmx.launcher.bean.StrokeWidth;
import com.qmx.launcher.callback.GlideImageLoader;
import com.qmx.launcher.callback.JsonCallback;
import com.qmx.launcher.constant.AppConstant;
import com.qmx.launcher.constant.ComParamContact;
import com.qmx.launcher.constant.EventConfig;
import com.qmx.launcher.event.BoardEvent;
import com.qmx.launcher.token.TokenManager;
import com.qmx.launcher.utils.SocketUtil;
import com.qmx.launcher.view.DlgMgr;
import com.qmx.launcher.view.FrameAnimation;
import com.qmx.launcher.view.SketchpadView;
import com.tencent.ilivesdk.ILiveConstants;
import com.tencent.ilivesdk.ILiveSDK;
import com.tencent.ilivesdk.core.ILiveRoomManager;
import com.tencent.ilivesdk.core.ILiveRoomOption;
import com.tencent.ilivesdk.listener.ILiveEventHandler;
import com.tencent.ilivesdk.view.AVRootView;
import com.tencent.ilivesdk.view.AVVideoView;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
 * Created by tencent on 2018/5/21.
 */
public class RoomActivity extends AppCompatActivity implements View.OnClickListener, ILiveRoomOption.onExceptionListener, ILiveRoomOption.onRoomDisconnectListener, SocketUtil.SocketDataCallback {
    private final static String TAG = "RoomActivity";
    private AVRootView avRootView;
    private TextView tvRoomId;
    private ImageView img_meeting_icon;
    //    private EditText etMsg;
    //    private MsgListView lvChatMsg;
    //    private ChatMsgAdapter msgAdapter;
    private int roomId = 0;
    private String isOpen = "0";//1：允许 0：静音
    private String muteType = "1";//1：允许.. 2:禁止.. \参会者自己解除静音
    private String uId = "";//要踢的用户ID
    private HashMap hashMap = new HashMap();

    LinearLayout ll_control;
    private boolean bFirstBackPress = true;
    private boolean bFrontCamera = false, bMicEnable = true, bLayoutEnable = true, bRecordEnable = true;
    private ImageView iv_layout, iv_record, iv_yun_file, iv_white_broad, iv_close_voice, iv_camera, iv_hang_up;
    //    private DrawBoardView white_board;
    private SketchpadView white_board;
    private RelativeLayout rl_white_board_layout;
    private LinearLayout ll_color_list;
    private Banner iv_banner;
    public SharedPreferences sharedPreferences;
    public SharedPreferences.Editor editor;
    List<Integer> list = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SocketUtil.getInstance();
        SocketUtil.getInstance().setSocketDataCallback(this);
        // 初始化UI
        initView();
        // 添加事件监听回调
        ILiveSDK.getInstance().addEventHandler(eventHandler);
    }

    private Context getContext() {
        return isFinishing() ? null : this;
    }

    //////////////////////////////////    TRTC主要流程   ////////////////////////////////////////

    /**
     * 加入音视频房间
     */
    private void enterTrtcRoom(int roomId) {
        // Step 3: 设置渲染控件
        ILiveRoomManager.getInstance().initAvRootView(avRootView);
        // 定制渲染控件
        customRootView(avRootView);

        // Step 4: 加入音视频房间
        ILiveRoomOption option = new ILiveRoomOption()
                .imsupport(false)       // 不需要IM功能
                .exceptionListener(this)  // 监听异常事件处理
                .roomDisconnectListener(this)   // 监听房间中断事件
                .controlRole("ed960")  // 使用user角色
                .autoCamera(true)       // 进房间后不需要打开摄像头
                .autoMic(true);         // 进房间后不需打开Mic
        // Step 4: 加入音视频房间
        if (roomId == sharedPreferences.getInt(AppConstant.ROOM_ID, 0)) {
            ILiveRoomManager.getInstance().createRoom(roomId, option);
            Log.i("enterTrtcRoom", "创建房间");
        } else {
            ILiveRoomManager.getInstance().joinRoom(roomId, option);
            Log.i("enterTrtcRoom", "加入房间");
        }
    }

    /**
     * 处理TRTC 事件
     */
    private ILiveEventHandler eventHandler = new ILiveEventHandler() {
        @Override
        public void onForceOffline(String userId, String module, int errCode, String errMsg) {
            DlgMgr.showMsg(getContext(), "帐号被踢下线: " + module + "|" + errCode + "|" + errMsg);
            finish();
        }

        @Override
        public void onCreateRoomSuccess(int roomId, String groupId) {
            DlgMgr.showToast(getContext(), "创建房间成功");
        }

        @Override
        public void onCreateRoomFailed(int roomId, String module, int errCode, String errMsg) {
            DlgMgr.showMsg(getContext(), "创建房间失败: " + module + "|" + errCode + "|" + errMsg);
        }

        @Override
        public void onJoinRoomSuccess(int roomId, String groupId) {
            DlgMgr.showToast(getContext(), "加入房间成功");
        }

        @Override
        public void onJoinRoomFailed(int roomId, String module, int errCode, String errMsg) {
            if (module.equals(ILiveConstants.Module_IMSDK) && (10010 == errCode || 10015 == errCode)) {
                ILiveRoomManager.getInstance().createRoom(roomId, new ILiveRoomOption()
                        .controlRole("user"));
            } else {
                DlgMgr.showMsg(getContext(), "加入房间失败: " + module + "|" + errCode + "|" + errMsg);
            }
        }

        @Override
        public void onQuitRoomSuccess(int roomId, String groupId) {
            finish();
        }

        @Override
        public void onQuitRoomFailed(int roomId, String module, int errCode, String errMsg) {
            DlgMgr.showMsg(getContext(), "退出房间失败: " + module + "|" + errCode + "|" + errMsg);
        }
    };

    //////////////////////////////////    UI处理   ////////////////////////////////////////

    @Override
    protected void onResume() {
        super.onResume();
        Intent intent = getIntent();
        if (null != intent) {
            roomId = intent.getIntExtra("roomId", 0);
            if (0 != roomId) {
                meetingRemain();
                enterTrtcRoom(roomId);
                infoMeeting();
                meetingInfo();
                timer.start();
                tvRoomId.setText("" + roomId);
            }
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.i("onKeyDown==", keyCode + "");
        if (ll_control.getVisibility() == View.VISIBLE) {
            if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
                if (timer != null) {
                    timer.cancel();
                    timer.start();
                }
                Log.i("timer==", "1111111111111111111111111");
            }
        }
        if (ll_control.getVisibility() == View.INVISIBLE) {
            if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
                //            timer.cancel();
                //            timer.start();
                Log.i("KEYCODE_ALT_LEFT==", keyCode + "");
                return true;
            }
        }
        if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER && ll_control.getVisibility() == View.VISIBLE) {
            Log.i("getVisibility==", keyCode + "");
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
            if (ll_control.getVisibility() == View.INVISIBLE) {
                ll_control.setVisibility(View.VISIBLE);
                avRootView.setFocusable(false);
                ll_control.setFocusable(true);
                if (rl_white_board_layout.getVisibility() == View.VISIBLE) {
                    ll_control.setNextFocusForwardId(R.id.ll_white_broad);
                    iv_white_broad.setFocusable(true);
                } else {
                    ll_control.setNextFocusForwardId(R.id.ll_layout);
                }
                ll_control.setNextFocusForwardId(R.id.ll_layout);
                timer.start();
                Log.i("INVISIBLE==", keyCode + "");
            } else {
                ll_control.setVisibility(View.INVISIBLE);
                avRootView.setFocusable(true);
                ll_control.setNextFocusForwardId(R.id.av_root_view);
                ll_control.setFocusable(false);
            }
            Log.i("KEYCODE_DPAD_CENTER==", keyCode + "");
        }
        return super.onKeyDown(keyCode, event);
    }


    @Override
    protected void onPause() {
        super.onPause();
        //取消注册，如果已经注册了，则取消注册
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        ILiveRoomManager.getInstance().onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        white_board.clearAllStrokes();
        white_board = null;
        meetingLeave();

        Log.d("meetingLeaveonDestroy", "onDestroy: 11111111111111111");
        ILiveSDK.getInstance().clearEventHandler();
        ILiveRoomManager.getInstance().quitRoom();
    }

    @Override
    public void onBackPressed() {
        if (bFirstBackPress) {
            bFirstBackPress = false;
            ILiveRoomManager.getInstance().quitRoom();
        } else {
            finish();
        }
    }

    @Override
    public void onClick(View v) {
        Log.i("onClick", v.getId() + "");
        switch (v.getId()) {
            case R.id.iv_layout:
                if (bLayoutEnable) {
                    ILiveRoomManager.getInstance().getRoomView().swapVideoView(0, 1);
                } else {
                    ILiveRoomManager.getInstance().getRoomView().swapVideoView(1, 0);
                }
                bLayoutEnable = !bLayoutEnable;
                break;
            case R.id.iv_record:
                bRecordEnable = !bRecordEnable;
                ILiveRoomManager.getInstance().enableMic(bRecordEnable);
                break;
            case R.id.iv_yun_file:
                yunFile();
                break;
            case R.id.iv_white_broad:
                if (rl_white_board_layout.getVisibility() == View.INVISIBLE) {
                    rl_white_board_layout.setVisibility(View.VISIBLE);
                    ll_color_list.setVisibility(View.VISIBLE);
                    ll_control.setVisibility(View.INVISIBLE);
                    avRootView.setFocusable(true);
                    ll_control.setNextFocusForwardId(R.id.av_root_view);
                    ll_control.setFocusable(false);
                    timer.start();
                } else {
                    rl_white_board_layout.setVisibility(View.INVISIBLE);
                    ll_color_list.setVisibility(View.INVISIBLE);
                    timer.start();
                }
                break;
            case R.id.iv_close_voice:
                if (bMicEnable) {
                    iv_close_voice.setImageResource(R.drawable.selector_meeting_open_voice);
                } else {
                    iv_close_voice.setImageResource(R.drawable.selector_meeting_close_voice);
                }
                bMicEnable = !bMicEnable;
                userEnableMic(bMicEnable);
                break;
            case R.id.iv_camera:
                if (bFrontCamera) {
                    iv_camera.setImageResource(R.drawable.selector_meeting_open_camera);
                } else {
                    iv_camera.setImageResource(R.drawable.selector_meeting_close_camera);
                }
                ll_control.setVisibility(View.INVISIBLE);
                avRootView.setFocusable(true);
                ll_control.setNextFocusForwardId(R.id.av_root_view);
                ll_control.setFocusable(false);
                userEnableCamera(ILiveRoomManager.getInstance().getCurCameraId(), bFrontCamera);
                break;
            case R.id.iv_meeting_hangup:
                ILiveRoomManager.getInstance().quitRoom();
                break;
        }
    }

    private LinearLayout initClickableLayout(int resId) {
        LinearLayout layout = (LinearLayout) findViewById(resId);
        layout.setOnClickListener(this);
        return layout;
    }

    private void initView() {
        setContentView(R.layout.room_activity);
        sharedPreferences = getSharedPreferences(QMXApplication.getInstance().getPackageName(), Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
        avRootView = (AVRootView) findViewById(R.id.av_root_view);
        img_meeting_icon = (ImageView) findViewById(R.id.img_meeting_icon);
        tvRoomId = (TextView) findViewById(R.id.tv_room_id);
        initClickableLayout(R.id.ll_layout);
        initClickableLayout(R.id.ll_record);
        initClickableLayout(R.id.ll_white_broad);
        initClickableLayout(R.id.ll_iv_yun_file);
        initClickableLayout(R.id.ll_close_voice);

        ll_control = initClickableLayout(R.id.ll_control);

        iv_layout = findViewById(R.id.iv_layout);
        iv_layout.setOnClickListener(this);
        iv_record = findViewById(R.id.iv_record);
        iv_record.setOnClickListener(this);
        iv_yun_file = findViewById(R.id.iv_yun_file);
        iv_yun_file.setOnClickListener(this);
        iv_white_broad = findViewById(R.id.iv_white_broad);
        iv_white_broad.setOnClickListener(this);
        iv_close_voice = findViewById(R.id.iv_close_voice);
        iv_close_voice.setOnClickListener(this);
        iv_camera = findViewById(R.id.iv_camera);
        iv_camera.setOnClickListener(this);
        iv_hang_up = findViewById(R.id.iv_meeting_hangup);
        iv_hang_up.setOnClickListener(this);


        ll_color_list = (LinearLayout) findViewById(R.id.ll_color_list);

        rl_white_board_layout = findViewById(R.id.rl_white_board_layout);
        rl_white_board_layout.setVisibility(View.INVISIBLE);

        white_board = findViewById(R.id.white_board);
        //        white_board.setShowToolsbar(this);

        iv_banner = (Banner) findViewById(R.id.iv_banner);
        iv_banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        iv_banner.setIndicatorGravity(BannerConfig.CENTER);
        iv_banner.setVisibility(View.INVISIBLE);
        iv_banner.setFocusable(false);
        iv_banner.setActivated(false);
        iv_banner.setClickable(false);

        //启动闪动动画
        new FrameAnimation(img_meeting_icon, getRes(), 60, true);

    }

    /**
     * 获取需要播放的动画资源
     */
    private int[] getRes() {
        TypedArray typedArray = getResources().obtainTypedArray(R.array.meeting_animation);
        int len = typedArray.length();
        int[] resId = new int[len];
        for (int i = 0; i < len; i++) {
            resId[i] = typedArray.getResourceId(i, -1);
        }
        typedArray.recycle();
        return resId;
    }

    CountDownTimer timer = new CountDownTimer(5000, 10) {
        @Override
        public void onTick(long millisUntilFinished) {

        }

        @Override
        public void onFinish() {
            if (rl_white_board_layout.getVisibility() == View.VISIBLE) {
                ll_control.setVisibility(View.INVISIBLE);
                rl_white_board_layout.setFocusable(true);
                ll_control.setNextFocusForwardId(R.id.rl_white_board_layout);
                ll_control.setFocusable(false);
            } else {
                ll_control.setVisibility(View.INVISIBLE);
                avRootView.setFocusable(true);
                ll_control.setNextFocusForwardId(R.id.av_root_view);
                ll_control.setFocusable(false);
            }
        }
    };
    //////////////////////////////////    渲染定制   ////////////////////////////////////////

    private void customRootView(final AVRootView rootView) {

        rootView.setGravity(AVRootView.LAYOUT_GRAVITY_RIGHT);     // 右侧展示小窗口
        rootView.setBackground(R.mipmap.com_bg);                  // 设置背景图片
        rootView.setDeviceRotation(270);

        rootView.setLocalRotationFix(90);
        rootView.setRemoteRotationFix(180);
        //        rootView.setLocalRotationFix(0);
        //        rootView.setRemoteRotationFix(0);

        rootView.setLocalFullScreen(true);
        //        rootView.setAutoOrientation(true);
        //        rootView.setReRotationResize(true);
        rootView.setSubCreatedListener(new AVRootView.onSubViewCreatedListener() {
            @Override
            public void onSubViewCreated() {
                for (int i = 0; i < ILiveConstants.MAX_AV_VIDEO_NUM; i++) {
                    final int index = i;
                    final AVVideoView videoView = rootView.getViewByIndex(i);
                    videoView.setIsPC(true);
                    if (i != 0) {
                        videoView.setDragable(true);
                    } else {

                    }
                    // 可拖动
                    videoView.setGestureListener(new GestureDetector.SimpleOnGestureListener() {
                        @Override
                        public boolean onSingleTapConfirmed(MotionEvent e) {        // 小屏点击交换
                            if (index == 0) {
                            } else {
                                rootView.swapVideoView(0, index);
                            }
                            return super.onSingleTapConfirmed(e);
                        }
                    });
                }
            }
        });
    }

    @Subscribe
    public void onEvent(final BoardEvent event) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    Object object = event.getObject();
                    switch (event.what) {
                        case EventConfig.POINT:
                            DrawBoardPoint point = (DrawBoardPoint) object;
                            handlePoint(point);
                            break;
                        case EventConfig.COMMAND:
                            Command command = (Command) object;
                            handleCommand(command);
                            break;
                        case EventConfig.COLOR:
                            SelectColor color = (SelectColor) object;
                            handleColor(color);
                            break;
                        case EventConfig.STROKE:
                            StrokeWidth strokeWidth = (StrokeWidth) object;
                            handleStroke(strokeWidth);
                            break;
                    }
                } catch (Exception e) {
                    Log.e(TAG, "handle board event fail");
                }

            }
        });
    }

    private void handleStroke(StrokeWidth strokeWidth) {
        int type = strokeWidth.getType();
        int width = strokeWidth.getStroke();
        switch (type) {
            case SketchpadView.STROKE_PEN:
                SketchpadView.setStrokeSize(width, SketchpadView.STROKE_PEN);
                break;
            case SketchpadView.STROKE_ERASER:
                SketchpadView.setStrokeSize(width, SketchpadView.STROKE_ERASER);
                break;
        }
    }


    private void handlePoint(DrawBoardPoint point) {
        int x = point.getX();
        int y = point.getY();
        switch (point.getState()) {
            case SketchpadView.ACTION_DOWN:
                white_board.action_down(x, y);
                break;
            case SketchpadView.ACTION_MOVE:
                white_board.action_move(x, y);
                break;
            case SketchpadView.ACTION_UP:
                white_board.action_up(x, y);
                break;
        }
    }

    private void handleCommand(Command command) {
        switch (command.getType()) {
            case SketchpadView.UNDO:
                white_board.undo();
                break;
            case SketchpadView.REDO:
                white_board.redo();
                break;
            case SketchpadView.CLEAR_BOARD:
                white_board.clearAllStrokes();
                break;
            default:
                white_board.setStrokeType(command.getType());
                break;
        }
    }

    private void handleColor(SelectColor color) {
        int rgb = Color.rgb(color.getR(), color.getG(), color.getB());
        white_board.setStrokeColor(rgb);
    }

    private AlertDialog inputDlg;

    private void showInputDialog() {
        if (null != inputDlg && inputDlg.isShowing()) {
            inputDlg.dismiss();
            inputDlg = null;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext(), R.style.full_dlg);
        builder.setTitle(R.string.str_problem_other);

        final EditText input = new EditText(getContext());
        input.setSingleLine(false);
        input.setTextColor(Color.BLACK);
        builder.setView(input);

        builder.setPositiveButton("提交", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

        inputDlg = builder.create();
        inputDlg.setCanceledOnTouchOutside(true);
        inputDlg.show();
    }

    @Override
    public void onException(int exceptionId, int errCode, String errMsg) {

    }

    @Override
    public void onRoomDisconnect(int errCode, String errMsg) {

    }

    @Override
    public void socketDataCallback(int code, JSONObject jsonObject) {
        switch (code) {
            case AppConstant.MESSAGE_EVENT_ID_USER_CAMERA_OPEN:
                userEnableCamera(ILiveRoomManager.getInstance().getActiveCameraId(), true);
                break;
            case AppConstant.MESSAGE_EVENT_ID_USER_CAMERA_CLOSE:
                userEnableCamera(ILiveRoomManager.getInstance().getActiveCameraId(), false);
                break;
            case AppConstant.MESSAGE_EVENT_ID_USER_MIC_OPEN:
                userEnableMic(true);
                break;
            case AppConstant.MESSAGE_EVENT_ID_USER_MIC_CLOSE:
                userEnableMic(false);
                break;
            case AppConstant.MESSAGE_EVENT_ID_USER_ALL_MUTE_1:
                Log.i("USER_ALL_MUTE_1==", code + "");
                break;
            case AppConstant.MESSAGE_EVENT_ID_USER_ALL_MUTE_2:
                Log.i("USER_ALL_MUTE_2==", code + "");
                break;
            case AppConstant.MESSAGE_EVENT_ID_MEETING_ROLLCALL_RECEIVE:
                Log.i("MEETING_ROLLCALL_RE", code + "");
                break;
            case AppConstant.MESSAGE_EVENT_ID_USER_CACHE_SUCCESS:
                break;
            case AppConstant.MESSAGE_EVENT_ID_MEETING_KICK_USER:
                break;
            case AppConstant.MESSAGE_EVENT_ID_MEETING_MAIN_ID:
                Log.i("MEETING_ROLLCALL_RE", code + "");
                break;
            case AppConstant.MESSAGE_EVENT_ID_MEETING_ROLL_CALL:
                Log.i("MEETING_ROLLCALL_RE", code + "");
                break;
            case AppConstant.MESSAGE_EVENT_ID_MEETING_DESTROY_ROOM:
                ILiveRoomManager.getInstance().quitRoom();
                break;
            case AppConstant.MESSAGE_EVENT_ID_MEETING_USER_LEAVE:

                break;
            case AppConstant.MESSAGE_EVENT_ID_USER_MIC_HELP:
                Log.i("MEETING_ROLLCALL_RE", code + "");
                break;
            case AppConstant.MESSAGE_EVENT_ID_USER_CHANGE_ROOT:

                break;
            case AppConstant.MESSAGE_EVENT_ID_USER_APPLY_ROOT:
                meetingChange(Integer.valueOf(jsonObject.opt("uid").toString()));
                break;
            case AppConstant.MESSAGE_EVENT_ID_WHITEBOARD_OPEN:
                rl_white_board_layout.setVisibility(View.VISIBLE);
                break;
            case AppConstant.MESSAGE_EVENT_ID_WHITEBOARD_CLOSE:
                rl_white_board_layout.setVisibility(View.INVISIBLE);
                break;
            case AppConstant.MESSAGE_EVENT_ID_WHITEBOARD_DATA:
                shareWhiteboard("0", jsonObject.toString());
                break;
            case AppConstant.MESSAGE_EVENT_ID_IMAGES_OPEN:
                Log.i("显示分享图片", code + "" + "json==" + jsonObject);
                Gson gson = new Gson();
                List<String> statusLs = gson.fromJson((String) jsonObject.opt("data"), new TypeToken<List<String>>() {
                }.getType());
                iv_banner.setVisibility(View.VISIBLE);
                iv_banner.setImages(statusLs)
                        .isAutoPlay(false)
                        .setImageLoader(new GlideImageLoader()).start();
                iv_banner.onPageSelected(0);
                break;
            case AppConstant.MESSAGE_EVENT_ID_IMAGES_CLOSE:
                Log.i("隐藏分享图片", code + "");
                iv_banner.setVisibility(View.INVISIBLE);
                break;
            case AppConstant.MESSAGE_EVENT_ID_IMAGES_EVENT:
                iv_banner.onPageSelected(Integer.valueOf(jsonObject.opt("data").toString()));
                Log.i("分享图片手势", code + "");
                break;
            case AppConstant.MESSAGE_EVENT_ID_SHARE_EVENT_ERROR:
                Log.i("错误事件", code + "");
                break;
        }
    }

    // 摄像头
    public void userEnableCamera(int cameraId, boolean enable) {
        ILiveRoomManager.getInstance().enableCamera(cameraId, enable);
        bFrontCamera = !bFrontCamera;
    }

    // 麦克风
    public void userEnableMic(boolean enable) {
        ILiveRoomManager.getInstance().enableMic(enable);
    }

    public void yunFile() {

        final FileDialogFragment dialog = new FileDialogFragment();
        dialog.show(getSupportFragmentManager(), "FileDialogFragment");

    }


    /**
     * 会议室缓存信息
     */
    public void infoMeeting() {
        OkGo.<String>post(AppConstant.Url + ComParamContact.Info.PATH)
                .params(ComParamContact.Info.TOKEN, TokenManager.getInstance().getAuthModel().getToken())
                .params(ComParamContact.Info.ROOM_ID, roomId)
                .execute(new JsonCallback<String>() {

                    @Override
                    public void onSuccess(Response<String> response) {

                    }

                    @Override
                    public void onError(Response<String> response) {
                        Log.i("onError", response.getException().getMessage());
                    }
                });
    }

    /**
     * 开启/关闭语音
     */
    public void meetingCamera() {
        hashMap.put("type", isOpen);
        hashMap.put("uid", uId);
        hashMap.put("room_id", roomId);
        SocketUtil.getInstance().sendSocketData("meeting@camera", hashMap);
        hashMap.clear();
    }

    /**
     * 主持人发起点名
     */
    public void hostCallNames() {
        hashMap.put("room_id", roomId);
        SocketUtil.getInstance().sendSocketData("meeting@rollcall", hashMap);
        hashMap.clear();
    }

    /**
     * 会议人员确认签到
     */
    public void meetingRemain() {
        hashMap.put("room_id", roomId);
        SocketUtil.getInstance().sendSocketData("meeting@remain", hashMap);
        hashMap.clear();
    }

    /**
     * 分享白板事件
     * #0:关闭画板, 1:打开画板, 2:发送画板数据
     */
    public void shareWhiteboard(String mType, String mWhiteboard) {
        hashMap.put("room_id", roomId);
        hashMap.put("type", mType);// 0|1|2, #0:关闭画板, 1:打开画板, 2:发送画板数据
        hashMap.put("data", mWhiteboard);//画板数据  //可选
        SocketUtil.getInstance().sendSocketData("share@whiteboard", hashMap);
        hashMap.clear();
    }

    /**
     * 分享图片事件
     * 'type' => 0|1|2, #0:关闭图片分享, 1:打开图片分享（此功能已转服务端）, 2:操作左右轮播事件
     * 'data' => null  #当type=1 传递图片元数据 | type=2 传递左右录播手势数据
     */
    public void shareImages(String mType, String shareImages) {
        hashMap.put("room_id", roomId);
        hashMap.put("type", mType);// 0|1|2, 0:关闭图片分享, 1:打开图片分享（此功能已转服务端）, 2:操作左右轮播事件
        hashMap.put("data", shareImages);//当type=1 传递图片元数据 | type=2 传递左右录播手势数据
        SocketUtil.getInstance().sendSocketData("share@images", hashMap);
        hashMap.clear();
    }

    /**
     * 主持人授权开麦
     */
    public void meetingMichael() {
        hashMap.put("room_id", roomId);
        hashMap.put("uid", sharedPreferences.getString(AppConstant.USER_ID, ""));
        hashMap.put("type", isOpen);
        SocketUtil.getInstance().sendSocketData("meeting@michael", hashMap);
        hashMap.clear();
    }

    /**
     * 开启/关闭语音
     */
    public void meetingMic() {
        hashMap.put("room_id", roomId);
        hashMap.put("type", isOpen);
        SocketUtil.getInstance().sendSocketData("meeting@mic", hashMap);
        hashMap.clear();
    }

    /**
     * 主持人发起全体静音
     */
    public void meetingMute() {
        hashMap.put("room_id", roomId);
        hashMap.put("type", muteType);
        SocketUtil.getInstance().sendSocketData("meeting@mute", hashMap);
        hashMap.clear();
    }

    /**
     * 主持踢人
     */
    public void meetingKick(String uId) {
        hashMap.put("room_id", roomId);
        hashMap.put("uid", uId);
        SocketUtil.getInstance().sendSocketData("meeting@kick", hashMap);
        hashMap.clear();
    }

    /**
     * 离开会议房间组
     */
    public void meetingLeave() {
        hashMap.put("room_id", roomId);
        SocketUtil.getInstance().sendSocketData("meeting@leave", hashMap);
        hashMap.clear();
    }

    /**
     * 销毁当前会议组
     */
    public void meetingDestroy() {
        hashMap.put("room_id", roomId);
        SocketUtil.getInstance().sendSocketData("meeting@destroy", hashMap);
        hashMap.clear();
    }

    /**
     * 申请主持人
     */
    public void meetingRoot() {
        hashMap.put("room_id", roomId);
        hashMap.put("password", "");
        SocketUtil.getInstance().sendSocketData("meeting@root", hashMap);
        hashMap.clear();
    }

    /**
     * 同步房间信息
     */
    public void meetingInfo() {
        hashMap.put("room_id", roomId);
        SocketUtil.getInstance().sendSocketData("meeting@info", hashMap);
        hashMap.clear();
    }

    /**
     * 当前主持人同意换位
     */
    public void meetingChange(int uid) {
        hashMap.put("room_id", roomId);
        hashMap.put("uid", uid);
        SocketUtil.getInstance().sendSocketData("meeting@change", hashMap);
        hashMap.clear();
    }


}
